package com.hongsen.cn.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.hongsen.cn.Utils.LogUtil;
import com.hongsen.cn.Utils.RxBus;
import com.hongsen.cn.adapter.GetOutOfLineAdapter;
import com.hongsen.cn.base.BaseFragment;
import com.hongsen.cn.bean.RxValue;
import com.hongsen.cn.bean.TheKeyPersonelBean;
import com.hongsen.cn.contract.OutOfLinePresenter;
import com.hongsen.cn.dayandmonth.R;
import com.hongsen.cn.dayandmonth.databinding.FragmentOutOfLineBinding;
import com.hongsen.cn.presenter.OutOfLineView;

import java.util.ArrayList;
import java.util.List;

import static com.hongsen.cn.bean.RxBusEventKey.HIDE_FRAGMENT_AND_SHOW;

/**
 * 今日违规
 */
public class GetOutOfLineFragment extends BaseFragment<OutOfLinePresenter> implements OutOfLineView, View.OnClickListener {

    private FragmentOutOfLineBinding binding;
    public List<TheKeyPersonelBean> list = new ArrayList<>();
    public GetOutOfLineAdapter adapter;


    @Override
    protected OutOfLinePresenter createPresenter() {
        return new OutOfLinePresenter(this);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getActivity())
                , R.layout.fragment_out_of_line, null, false);
        binding.setFragment(this);
        initView();
        presenter = new OutOfLinePresenter(this);
        presenter.getTheKeyPersonel("1");
        return binding.getRoot();
    }

    private void initView() {
        binding.rlModule.setLayoutManager(new LinearLayoutManager(getActivity()));
        binding.rlModule.setItemAnimator(new DefaultItemAnimator());
        adapter = new GetOutOfLineAdapter(getActivity(), list,"1");
        binding.rlModule.setAdapter(adapter);

        binding.btnBack.setOnClickListener(this);
    }


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_out_of_line;
    }

    @Override
    protected void initToolbar(Bundle savedInstanceState) {

    }

    @Override
    protected void initData() {

    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        if (!hidden) {
        }
    }

    /**
     * @param type
     */
    @Override
    public void getTheKeyPersonel(String type, final List<TheKeyPersonelBean> listBeans) {
        list.addAll(listBeans);
        adapter.notifyDataSetChanged();
        binding.tvModuleTitle.setText("今日违规("+ list.size() + "）");
    }

    @Override
    public void onClick(View v) {
        int sS_ID = v.getId();
        if (sS_ID == R.id.btnBack) {
            RxBus.getDefault().post(new RxValue(HIDE_FRAGMENT_AND_SHOW,"1"));
        }
    }
}
